package com.meego.common.misc;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class SafeListIterator<T> implements Iterator {

    private List<T> mList;
    private ArrayList<T> mScan;
    private int mPos = -1;

    public SafeListIterator(List<T> aList) {
        this.mList = aList;
        this.mScan = new ArrayList(this.mList);
    }

    @Override
    public boolean hasNext() {
        return this.mPos + 1 < this.mScan.size();
    }

    @Override
    public T next() {
        return this.mScan.get(++this.mPos);
    }

    @Override
    public void remove() {
        synchronized (this.mList) {
            this.mList.remove(this.mScan.get(this.mPos));
        }
    }
}
